<template>
  <div class="markdown" v-if="text">
    <v-md-preview :text="text"></v-md-preview>
  </div>
</template>

<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { useMenu } from "@/store/menu";
import { useAllFiles } from "@/store/allFiles";
const fileStore = useAllFiles();
const store = useMenu();
let text = ref("");
let url = computed(() => store.activeKey);
watch([() => url.value], ([newUrl]) => {
  getInfo(newUrl);
});
const getInfo = async (url: string) => {
  let file = fileStore.searchFileByPath(url);
  let fileCode = (await file?.moduleToString()) as string;
  text.value = fileCode;
};
getInfo(url.value);
</script>

<style lang="scss" scoped></style>
